package com.gzmu.myprint.mapper;


import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gzmu.myprint.model.PrintUser;
import org.apache.ibatis.annotations.*;

@Mapper
public interface PrintUserMapper extends BaseMapper<PrintUser> {
    @Select("SELECT * FROM sc_user WHERE openid=#{openid}")
    PrintUser findUerByOpenId(@Param("openid") String openid);

    @Insert("INSERT INTO sc_user(openid,nickName,name,gender,avatarUrl,money,phone,time,role) " +
            "VALUES (#{openid},#{nickName},#{name},#{gender},#{avatarUrl},#{money},#{phone},#{time},#{role})" +
            "ON DUPLICATE KEY UPDATE nickName = #{nickName},name = #{name},gender = #{gender},avatarUrl = #{avatarUrl},phone = #{phone},time = #{time},role = #{role}")
    @Options(useGeneratedKeys = true, keyProperty = "id")
    int InsertOrUpUser(PrintUser user);

    @Select("SELECT max(id) FROM sc_user")
    int getLastUid();

    @Select("SELECT * FROM sc_user WHERE id=#{id}")
    PrintUser findUserByUid(@Param("id") int id);

    @Update("UPDATE sc_user set money = #{money} WHERE id=#{id}")
    int upDateUserOfPrice(@Param("id") int uid, @Param("money") double money);
}
